<?php
class InfoAction extends GlobalAction{
    public function index(){
    	$this->info_list();
    }
    public function info_list(){
    	$info = M('info');
    	import("@.ORG.Page"); //导入分页类 
        $count = $info->count();    //计算总数 
        $p = new Page ( $count, 30 ); 
    	$info = $info->limit($p->firstRow.','.$p->listRows)->order('sorting asc,info_id asc')->findall();
    	$page = $p->show (); 
        $this->assign( "page", $page ); 
    	$this->assign('info',$info);
    	$this->GlobalName();
		$this->display('list');
    }
    public function add(){
    	$this->GlobalName();
		$this->display();
    }
    public function info_news_get(){
    	$_POST['time'] = time();
    	$info = M('info');
    	$info->create();
    	if ($info->add()) {
    		$this->get_alert('新增成功');
    	};
    	$infoid = mysql_insert_id();
    	$menu = M('menu');
    	$_POST['url'] = '?a=info&infoid='.mysql_insert_id();
    	$menu->create();
    	if ($menu->add()) {
    		$this->get_alert('新增导航成功');
    	};
    	
    	$info->find($infoid);
    	$info->meid = mysql_insert_id();
    	$info->save();
    }
    
    public function edit(){
    	$pid = $_GET['pid'];
    	$info = M('info');
    	$info = $info->where('info_id = '.$pid)->findall();
    	$this->assign('info',$info);
    	$this->GlobalName();
		$this->display();
    }
    public function info_edit_get(){
    	$info = M('info');
    	$info->create();
    	if ($info->save()) {
    		$this->get_alert('修改成功');
    	};
    	$menu = M('menu');
    	$menu->find($_POST['meid']);
    	$menu->title = $_POST['title'];
    	$menu->e_title = $_POST['e_title'];
    	if ($menu->save()) {
    		$this->get_alert('导航修改成功');
    	};
    }
    
    
    
    public function info_delete(){
    	$info = M('info');
    	$del = $_POST['del'];
    	$delete = $del[0];
    	for ($i=1;$i < count($del);$i++){
    		$delete = $delete.','.$del[$i];
    	}
    	if ($info->delete($delete)) {
    		$this->get_alert('删除成功');
    	};
    }
    
    public function ajax_show(){
    	$this->ajax_get('info','show_m');
    }
    
    public function left(){//默认左列表
    	$left = array(
    		array('sort'=>'Info','name'=>'单页管理','value'=>'info_list'),
    		array('sort'=>'Info','name'=>'新增单页','value'=>'add')
    	);
     	$this->assign('user',$_SESSION['User']);
    	$this->assign('sort',$sort);
    	$this->assign('left',$left);
    	$this->display('Index:left');
    }
}
?>